﻿
Imports std

Namespace seriousLogUploader
    Public Module seriousLogUploader
        Private Class _seriousLogUploader
            Inherits uploader(Of String)

            Protected Overrides Sub addWriteEventHandler()
                AddHandler errorHandle.writeLog, AddressOf writeLogHandler
            End Sub

            Private Sub writeLogHandler(ByVal errtype As errorHandle.errorType, ByVal errtypeChar As Char, _
                                        ByVal msg As String)
                If errtype = errorHandle.errorType.critical OrElse _
                   errtype = errorHandle.errorType.exclamation OrElse _
                   errtype = errorHandle.errorType.other Then
                    push_queue(msg)
                End If
            End Sub

            Protected Overrides Sub removeWriteEventHandler()
                RemoveHandler errorHandle.writeLog, AddressOf writeLogHandler
            End Sub

            Protected Overrides Function upload(ByVal v As String) As Boolean
                Return talk.write(applicationSign() + ".serious.log", encoding.utf8().GetBytes(v + newline.incode()))
            End Function
        End Class

        Private _uploader As _seriousLogUploader = Nothing

        Sub New()
            _uploader = New _seriousLogUploader()
        End Sub

        Public Function initial(ByVal storoom As pair(Of String, Int32)) As Boolean
            Return _uploader.initial(storoom)
        End Function

        Public Function initial() As Boolean
            Return _uploader.initial()
        End Function
    End Module
End Namespace
